package com.spring.cloud.controller;

import com.spring.cloud.enums.SuccessMsgEnum;
import com.spring.cloud.pojo.User;
import com.spring.cloud.service.UserService;
import com.spring.cloud.utils.JsonResultUtil;
import com.spring.cloud.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public JsonResult addUser(@Valid @RequestBody User user){

        userService.addUser(user);
        return JsonResultUtil.ok(SuccessMsgEnum.S0);
    }

    /**
     * 根据用户名和密码查询用户
     * @param username
     * @param password
     * @return
     */
    @GetMapping("/query")
    public User queryUser(@RequestParam("username") String username, @RequestParam("password") String password) {
        return userService.queryUser(username, password);
    }


}
